<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="商品名称">
                <a-input placeholder="请输入商品名称" v-model="queryParam.name" allowClear></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getList()">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :border="false">
      <div class="table-operator" style="display: flex; justify-content: space-between">
        <a-radio-group v-model="queryParam.status" @change="getList()">
          <a-radio-button v-for="item of statusList" :key="item.id" :value="item.id"> {{ item.name }} </a-radio-button>
        </a-radio-group>

        <div style="display: flex">
          <a-button type="primary" style="margin-right: 10px" @click="$refs.AddGoodsTable.visible = true"
            >+ 新增</a-button
          >
          <a-dropdown>
            <a-menu slot="overlay">
              <a-menu-item @click="handleAll('remove')">批量删除</a-menu-item>
              <a-menu-item @click="handleAll('change', '1')" v-if="queryParam.status != '1'">批量开启</a-menu-item>
              <a-menu-item @click="handleAll('change', '0')" v-if="queryParam.status != '0'">批量关闭</a-menu-item>
            </a-menu>
            <a-button> 批量操作 </a-button>
          </a-dropdown>
        </div>
      </div>

      <GoodsTable :queryParam="queryParam" ref="GoodsTable"></GoodsTable>
    </a-card>
    <AddGoodsTable @add="add" ref="AddGoodsTable"></AddGoodsTable>
  </page-header-wrapper>
</template>

<script>
import GoodsTable from './components/GoodsTable'
import AddGoodsTable from './components/AddGoodsTable'
import { videoGoodsAddGoods } from '@/api/videoClassify'

export default {
  components: {
    GoodsTable,
    AddGoodsTable,
  },

  data() {
    return {
      queryParam: {
        name: undefined,
        status: '-1',
      },
      list: [],

      statusList: [
        { id: '-1', name: '全部', color: 'blue', statusText: '-' },
        { id: '1', name: '已开启', color: 'green', statusText: '已开启' },
        { id: '0', name: '已关闭', color: 'red', statusText: '已关闭' },
      ],
    }
  },

  methods: {
    getList() {
      this.$refs.GoodsTable.refresh()
    },

    // 批量操作
    handleAll(type, status) {
      this.$refs.GoodsTable.updateAll(type, status)

      // switch (type) {
      //   case 'remove':
      //     // console.log('remove')
      //     break

      //   case 'change':
      // break
      // }
    },

    add(goods_id) {
      videoGoodsAddGoods({
        goods_id,
      }).then((res) => {
        if (res.code === 0) {
          this.$message.success(res.msg)
          let el = this.$refs.AddGoodsTable
          el.refresh()
          el.visible = false
          this.getList()
        }
      })
    },
  },
}
</script>

<style lang="less" scoped>
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 0 18px 0;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-right: 20px;
  }
}
</style>
